package com.bii.gelapp;

import java.io.IOException;
import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class CalculateFullscreenActivity extends Activity {
	public Bitmap originalBmp; // origin
	public static ArrayList<ConnectedComponent> componentlist = new ArrayList<ConnectedComponent>();
	public static ArrayList<ConnectedComponent> markerlist = new ArrayList<ConnectedComponent>();
	public static ArrayList componentvalues = new ArrayList();

	public CalculateTouchImageView imgView;

	public Menu menu;
	boolean editmode = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.calculatefullscreenactivity);
		if (getIntent().hasExtra("componentlist")) {
			componentlist = (ArrayList<ConnectedComponent>) getIntent()
					.getSerializableExtra("componentlist");
		}
		if (getIntent().hasExtra("markerlist")) {
			markerlist = (ArrayList<ConnectedComponent>) getIntent()
					.getSerializableExtra("markerlist");
		}
		if (getIntent().hasExtra("componentvalues")) {
			componentvalues = (ArrayList) (getIntent()
					.getSerializableExtra("componentvalues"));
		}

		try {
			originalBmp = InternalStorage.readBitmap(this, "colorBmp");
			imgView = new CalculateTouchImageView(this, originalBmp);
			imgView.setMaxZoom(8f);

			setContentView(imgView);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu1) {
		// TODO Auto-generated method stub
		this.menu = menu1;
		getMenuInflater().inflate(R.menu.calculatemenu, menu1);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
			case R.id.btInstant:
				if (editmode == false) {
					editmode = true;
					item.setTitle("Stop getting values");
					CalculateTouchImageView.editmode = true;
				} else {
					editmode = false;
					item.setTitle("Get value at point");
					CalculateTouchImageView.editmode = false;
				}
				break;
			case R.id.btExport:
				Bitmap exportbmap = CalculateTouchImageView.exportFinalImage();
				ExportSaveDialog esd = new ExportSaveDialog(this, exportbmap);
				esd.show();
				break;
	
		}

		return true;
	}
}
